package hot100.logos11To20;

/**
 * @author logos
 * date 2025/7/12 10:47
 * @version v1.0
 * @Package hot100
 */
public class logos20 {


    /**
     * 20.旋转图像
     * https://leetcode.cn/problems/rotate-image/?envType=study-plan-v2&envId=top-100-liked
     */
    class Solution {
        public void rotate(int[][] matrix) {
            int n = matrix.length;
            // 先转置矩阵
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    int tmp = matrix[i][j];
                    matrix[i][j] = matrix[j][i];
                    matrix[j][i] = tmp;
                }
            }
            // 再翻转每一行
            for (int[] row : matrix) {
                for (int j = 0; j < n / 2; j++) {
                    int tmp = row[j];
                    row[j] = row[n - 1 - j];
                    row[n - 1 - j] = tmp;
                }
            }
        }
    }
}
